/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package facade;

/**
 *
 * @author Diegoarpar
 */


import dao.*;
import entities.*;
import java.util.ArrayList;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;


public class facadeClass {
final EntityManagerFactory emf = Persistence.createEntityManagerFactory("satacreditoclientePU");
        EntityManager em;    
    public facadeClass() {
      try{
        em= emf.createEntityManager();    
     }catch(Throwable i){
        throw new RuntimeException (i);
      }
    }
     
    public final EntityManager getEntityManager(){
        if(!em.isOpen()){
            em=emf.createEntityManager();
            return em;
            }else
        return em;
        }

    public void create(Trace object)  {
      TraceDAO traceDao= new TraceDAO();

        try{
        getEntityManager().getTransaction().begin();
          /*
           * PERSIST Trace
           */
            traceDao.create(getEntityManager(),object);
        getEntityManager().getTransaction().commit();
         }   
        catch(Exception i){    
        }
        finally{
              getEntityManager().close();
          }         
    }
    public void create(Franchise object)  {
      FranchiseDAO franchiseDao= new FranchiseDAO();
        try{
        getEntityManager().getTransaction().begin();
          /*
           * PERSIST FRANCHISE
           */
            franchiseDao.create(getEntityManager(),object);
        getEntityManager().getTransaction().commit();
         }   
        catch(Exception i){        
        }
        finally{
              getEntityManager().close();
          }         
    }
    public void create(DocumentType object)  {
      DocumentTypeDAO documentTypeDao= new DocumentTypeDAO();
        try{
        getEntityManager().getTransaction().begin();
          /*
           * PERSIST DocumentType
           */
            documentTypeDao.create(getEntityManager(),object);
        getEntityManager().getTransaction().commit();
         }   
        catch(Exception i){        
        }
        finally{
              getEntityManager().close();
          }         
    }
    
    public void create(TraceState object)  {
      TraceStateDAO traceStateDao= new TraceStateDAO();
        try {
            getEntityManager().getTransaction().begin();
            /*
             * PERSIST TraceState
             */
            traceStateDao.create(getEntityManager(), object);
            getEntityManager().getTransaction().commit();
        }
        catch(Exception i){        
        }
        finally{
              getEntityManager().close();
          }         
    }
    
    public void create(Archive object)  {
      ArchiveDAO archiveDao= new ArchiveDAO();
        try{
        getEntityManager().getTransaction().begin();
          /*
           * PERSIST Archive
           */
            archiveDao.create(getEntityManager(),object);
        getEntityManager().getTransaction().commit();
         }   
        catch(Exception i){        
        }
        finally{
              getEntityManager().close();
          }         
    }
}